package com.zkingsoft.services.pc.impl;

import com.zkingsoft.services.pc.PcMenuDetailService;
import com.zkingsoft.services.pc.PcMenuRecordService;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.model.pc.PcMenuDetail;
import com.zkingsoft.model.pc.PcMenuRecord;
import com.zkingsoft.dao.pc.PcMenuDetailDao;
import com.zkingsoft.dao.pc.PcMenuRecordDao;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.Map;

import com.zkingsoft.exception.GlobleException;
import com.zkingsoft.util.ModelUtils;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import javax.annotation.Resource;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2017-03-23 15:08
 */
@Service("pcMenuRecordService")
public class  PcMenuRecordServiceImpl implements    PcMenuRecordService  {

	
	@Autowired
	private PcMenuRecordDao pcMenuRecordDao;
	@Resource
	private PcMenuDetailService pcMenuDetailService;
	
	@Transactional
	@Override
	public int add(PcMenuRecord pcMenuRecord){
		int m=pcMenuRecordDao.insert(pcMenuRecord);
		List<PcMenuRecord> list=pcMenuRecordDao.selectByModel(pcMenuRecord);
		for(PcMenuRecord p:list){
			pcMenuRecord=p;
		}
		pcMenuDetailService.addDetail(pcMenuRecord);
		return m;
		
	}
	
	@Override
	public int batchAdd(List<PcMenuRecord>  pcMenuRecordList) {
		int num = 0;

		int c = 10000;
		int size = pcMenuRecordList.size()/c + 1;
		for(int i=0; i<size; i++) {
			int begin = i*c;
			int end = (i+1)*c;
			end = end >= pcMenuRecordList.size() ? pcMenuRecordList.size() : end;
			List<PcMenuRecord> insertList = pcMenuRecordList.subList(begin, end);
			num += pcMenuRecordDao.batchInsert(insertList);
		}
		return num;
		
	}
	
	
   	
    @Override
	public int modifyByMap(PcMenuRecord oldPcMenuRecord
	,PcMenuRecord newPcMenuRecord){
	
		if (!ModelUtils.isModified(oldPcMenuRecord, newPcMenuRecord)) {
			return 1;
		}
		Map<String, Object> modifyMap=null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldPcMenuRecord, newPcMenuRecord);
		} catch (Exception e) {
			throw new GlobleException("���ݶԱ�ʧ��");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("menId", oldPcMenuRecord.getMenId());
			pcMenuRecordDao.updateByMap(modifyMap);
		}
		return 1;
	}
	
	@Override
	public int modifyByModel(PcMenuRecord pcMenuRecord){
	
		return pcMenuRecordDao.updateByModel(pcMenuRecord);
	
	}
	@Override
	public int remove(List<Long> list){
		PcMenuDetail pcMenuDetail=new PcMenuDetail();
		for(Long id:list){
			pcMenuDetail.setMrId(id);
			pcMenuDetailService.removeByModel(pcMenuDetail);
		}
		return pcMenuRecordDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(Long menId){
	
		return pcMenuRecordDao.deleteById(menId);
	
	}
	
	@Override
	public int removeByModel(PcMenuRecord pcMenuRecord){
	
		return pcMenuRecordDao.deleteByModel(pcMenuRecord);
	
	}
	
	
	@Override
	public List<PcMenuRecord> findInPage(PcMenuRecord pcMenuRecord,  PaginationVO pageVo){
		pageVo.setSort("men_week_sign");
		pageVo.setOrder("ASC");
		return pcMenuRecordDao.selectInPage(pcMenuRecord , pageVo);
	
	}
	
	@Override
	public List<PcMenuRecord> findByModel(PcMenuRecord pcMenuRecord){
	
		return pcMenuRecordDao.selectByModel(pcMenuRecord);
	
	}
	
	@Override
	public int  findTotal(PcMenuRecord pcMenuRecord){
	
		return pcMenuRecordDao.selectTotalRecord(pcMenuRecord);
	
	}
	
	@Override
	public PcMenuRecord  findById(Long menId){
	
		return pcMenuRecordDao.selectById(menId);
	
	}

	@Override
	public List<PcMenuRecord> findByTime(Date startTime,Date endTime) {
		
	    return pcMenuRecordDao.selectByTime(startTime, endTime);
	}

	

   	
	
	
}